package cn.usian.controller;

import cn.usian.pojo.Result;
import cn.usian.pojo.User;
import cn.usian.service.UserService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin //允许跨域访问
@RequestMapping("/user")
@RestController
public class LoginController {
    @Resource
    private UserService userService;

    @GetMapping("/login")
    public Result login(User user){
        Result result = new Result();
        if(user.getName().equals("lzm")&&user.getPassword().equals("123456")){
            result.setCode(1);
            result.setMsg("登陆成功");
        }else{
            result.setCode(0);
            result.setMsg("登陆失败");
        }
        return result;
    }



    @RequestMapping("/findAll")
    public List<User> findAll(){
        return userService.findAll();
    }
    @GetMapping("del")
    public void del(Integer id){
        userService.del(id);
    }
}
